package com.fast.controller.login;

import cn.hutool.jwt.JWT;
import cn.hutool.jwt.JWTPayload;
import cn.hutool.jwt.JWTUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @author hjw
 * @since 2022年03月24日 10:19:00
 */
@ApiModel("用户对象")
@Data
public class User {
    @ApiModelProperty("用户名中文名")
    private String username;

    @ApiModelProperty("密码")
    private String pwd;

    @ApiModelProperty("手机号")
    private String mobile;

    @ApiModelProperty("登录名")
    private String loginName;

    public static void main(String[] args) {

        Map<String,Object> payload = new HashMap<>();
        //签发时间
        payload.put(JWTPayload.ISSUED_AT,new Date());
        //过期时间，10秒后过期
        payload.put(JWTPayload.EXPIRES_AT,new Date(System.currentTimeMillis()+10000));
        //生效时间
        payload.put(JWTPayload.NOT_BEFORE,new Date());
        //载荷
        payload.put("username","zhangsan");
        String token = JWTUtil.createToken(payload, "ceshi".getBytes());
        System.out.println("token = " + token);

        String token1 = JWT.create().setPayload("name", "zhangsan").setKey("ceshi".getBytes()).setExpiresAt(new Date(System.currentTimeMillis() + 10000)).sign();
        System.out.println("token1 = " + token1);
    }
}
